<? session_start();

include("SVsystem/config/dbconfig.php"); ////////setup
include("SVsystem/class/clases.php");
include("SVsystem/config/dominio.php");

$tool = new formulario('db');
$tool2 = new tools;
$tool2->dbc = $tool->dbc; 


if(!isset($_SESSION['CLIENTE_ID'])) $tool->redirect("index.php");

if(isset($_REQUEST['borrar'])){ $tool->query("delete from orden_compra where id = '{$_REQUEST['borrar']}' "); $tool->redirect($PHP_SELF); }


 $datau = $tool->simple_db("SELECT 
  c.nombre,
  c.password,
  c.empresa,
  c.actividad,
  c.cargo,
  c.email2,
  c.web,
  c.email,
  c.tlf1,
  c.celular,
  c.tlf2,
  c.fax,
  c.zip,
  c.estado,
  c.ciudad,
  c.pais,
  c.notas,
  c.noticias_titulo,
  c.noticias_texto,
  group_concat(a.ruta) as archivos,
  group_concat(a.descrip) as descrips
FROM
  cliente c
  INNER JOIN cliente_archivo a ON (c.id = a.cliente_id) where c.id = '{$_SESSION['CLIENTE_ID']}' "); 
 
  $archivos = explode(',',$datau['archivos']);
  $descs = explode(',',$datau['descrips']);
  
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<title>Página personal de <?php echo utf8_encode($datau['nombre']); ?></title>
	<link rel="stylesheet" href="estilo.css" type="text/css" media="screen" title="no title" charset="utf-8">
	<script src="/SVsystem/js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="/SVscripts/menu.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="SVsystem/js/utils.js"></script>
<script type="text/javascript" src="SVsystem/js/banner-mouseover.js"></script>
<script type="text/javascript" src="SVsystem/js/ajax.js"></script>
</head>
<body>
<?php include('SVG-header.php'); ?>
<div id="wrapper">
	<div id="contenido">
		<div id="izquierda">
			<?php include('SVG-menu-categorias.php'); ?>
		</div>
		<div id="centro">
				<div id="userhome">
					<table width="566" border="0" align="center" cellpadding="0" cellspacing="0">
					<tr>
					<td>
                     <?php if(!empty($datau['noticias_titulo'])){ ?>
                    <div class="userhome-titulo"><?php echo $datau['noticias_titulo']; ?></div>
					 <div class="userhome-notas"><?php echo $datau['noticias_texto']; ?></div>
                    <?php } ?>


<div class="userhome-separador">.</div>



                    <div class="userhome-titulo">Bienvenido(a) <?php echo utf8_encode($datau['nombre']); ?></div>
					 <div class="userhome-notas"><?php echo $datau['notas']; ?></div>


                    

<div class="userhome-separador">.</div>


                     <div class="userhome-titulo">Su informaci&oacute;n Personal</div>
            
					<table width="100%" border="0" cellspacing="5" cellpadding="0">
                    <tr>
                    <td width="50%" class="userhome-tablaheader">Email</td>
                    <td width="50%" class="userhome-tablaheader">Teléfono</td>
                    </tr>
                    <tr>
                    <td class="userhome-tabladato"><span class="valor"><?php echo $datau['email'] ?></span></td>
                    <td class="userhome-tabladato"><span class="valor"><?php echo $datau['tlf1'] ?></span></td>
                    </tr>
                    <tr>
                    <td colspan="2" class="userhome-tablaheader">Compa&ntilde;ía</td>
                    </tr>
                    <tr>
                    <td colspan="2" class="userhome-tabladato"><span class="valor"><?php echo $datau['empresa'] ?></span></td>
                    </tr>
                    <tr>
                      <td class="userhome-tablaheader">Ciudad</td>
                      <td class="userhome-tablaheader">Pa&iacute;s</td>
                    </tr>
                    <tr>
                      <td class="userhome-tabladato"><span class="valor"><?php echo $datau['ciudad'] ?></span></td>
                      <td class="userhome-tabladato"><span class="valor"><?php echo $datau['pais'] ?></span></td>
                    </tr>
                    </table>

					<a href="javascript:popup('SV-popup-registro-edit.php', 'reg','600','800');">
					<div class="userhome-boton">Cambiar...</div>
					 </a>

<div class="userhome-separador">.</div>

				<?php 
	
				  ////ordenes de compra
				  
				  $tool->query("select o.id,date_format(o.fecha,'%d/%m/%Y') as fecha,estatus,o.monto,count(i.id) as nprod,
					(select nombre from producto where id = i.prod_id limit 1) as producto,																					   
				  (c.nombre) as cliente, c.email
				   from orden_compra o inner join orden_item i
				 on (o.id = i.orden_id)
				  INNER JOIN cliente c  ON (o.cliente_id = c.id)
				  where c.id = '{$_SESSION['CLIENTE_ID']}'
				  group by i.orden_id  ");
			  
			  
				  if($tool->nreg>0){
			  
				  ?>


					<div class="userhome-titulo">Órdenes de Compra Realizadas</div>


					<table width="100%" border="0" cellspacing="5" cellpadding="0">
					<tr>
					<td width="229" class="userhome-tablaheader">Productos</td>
					<td width="111" class="userhome-tablaheader">Precio (Bs)</td>
					<td width="106" class="userhome-tablaheader">Fecha</td>
					<td width="117" class="userhome-tablaheader">Status</td>
					</tr>
                    
			 <?php while ($row = mysql_fetch_assoc($tool->result)) { ?>
                    
					<tr>
					<td class="userhome-tabladato"><a href="javascript:popup('SV-popup-shoppingcart-readonly.php?id=<?php echo $row['id'] ?>', 'reg','600','900');"><?php echo $row['producto'] ?></a></td>
					<td class="userhome-tabladato"><?php echo number_format($row['monto'],2); ?></td>
					<td class="userhome-tabladato"><?php echo $row['fecha'] ?></td>
					<td class="userhome-tabladato">
                    <strong><?=$row['estatus'] ?></strong>
				<?php if($row['estatus']=="nueva"){ ?><a href="SV-userhome.php?borrar=<?php echo $row['id'] ?>"  title="Orden sin procesar, puedes borrarla"><img src="./img/delete.png" alt="" border="0" width="16" height="16" /></a>				<?php } ?>
                    
                    </td>
					</tr>
                    
             <?php } ?>        
                    
                    
					</table>

                    
                    
                    

					<?php } $tool->liberar(); ?> 
                    
                    
                    
                    
                    

					<div class="userhome-separador">.</div>
                    
                    
                    
				<?php 
                
                ////reportes de pago
                
                $tool->query("SELECT DISTINCT 
              p.monto,
              date_format(p.fecha,'%d/%m/%Y') AS fecha,
               (CASE p.estatus WHEN 1 THEN 'Realizado'  WHEN 2 THEN 'Rechazado' ELSE 'En proceso' END) as estatus,
              p.comentario
            FROM
              pago p
            WHERE
              p.cliente_id = '{$_SESSION['CLIENTE_ID']}' ");
                
                
                if($tool->nreg>0){
                
                ?>

					<div class="userhome-titulo">Sus Pagos&nbsp; Realizados</div>


					<table width="100%" border="0" cellspacing="5" cellpadding="0">
					<tr>
					 <td width="229" class="userhome-tablaheader">Concepto</td>
					<td width="111" class="userhome-tablaheader">Fecha</td>
					<td width="106" class="userhome-tablaheader">Monto (Bs)</td>
					<td width="117" class="userhome-tablaheader"> Status</td>
					</tr>
					
                    
                     <?php while ($row = mysql_fetch_assoc($tool->result)) { ?>
                    <tr>
					 <td class="userhome-tabladato"><?php echo $row['comentario'] ?></td>
					<td class="userhome-tabladato"><?php echo $row['fecha'] ?></td>
					<td class="userhome-tabladato"><?php echo number_format($row['monto'],2); ?></td>
					<td class="userhome-tabladato"><strong><?php echo $row['estatus'] ?></strong></td>
					</tr>
                    
                     <?php } ?>
                    
                    
					</table>
                    
                <?php } $tool->liberar(); ?>     
                    
<a href="javascript:popup('SV-popup-form-pago.php', 'reg','600','800');">
                    <div class="userhome-boton2">
                    Reportar pago
                    </div>
                    </a>

<div class="userhome-separador">.</div>

                    

    			<?php if(!empty($archivos[0])){ ?>
                   <div class="userhome-titulo">Documentos para usted</div>
						<div class="userhome-adjuntos">
						<?php for($ii=0;$ii<count($descs);$ii++){ ?>
                        <h3><a target="_blank" href="<?php echo $DOMINIOSV ?>/usuario/doc/<?php echo $archivos[$ii];  ?>"><?php echo $archivos[$ii] ?></a></h3>
						<p><?php echo $descs[$ii] ?></p>
						<?php } ?>
						</div>
                    
                    
                    <?php } ?>



	

					</td>
					</tr>
					</table>
				</div>
		</div>
		<div id="derecha">
			
              <?php if(empty($_SESSION['CLIENTE_ID'])){
            
                    //////////en el caso de que se decida hacer log in
                    include("login_flow.php");
                    ?>
            <!-- INCLUIR user-login.php o usuario-logead.php -->
                 <?php include('SVG-login.php'); ?>	
               <?php  }else{ ?>
                  <?php include('SVG-barra-usuario.php'); ?>
                <?php }?>
            
				<div  class="banners">
					<?php include('SVG-banners.php'); ?>
				</div>		
		</div>
	<div id="separador"></div>
<!--fin del div de contenido -->
</div>


	<div id="fincontenido"></div>
<?php include('SVG-footer.php'); ?>